<template>
  <a-card title="消息提醒" class="card">
    <template #extra>
      <a-link>查看更多</a-link>
    </template>
    <div v-if="formModel.listData.length !== 0" class="content">
      <div v-for="item in formModel.listData" :key="item.id" class="cellOut">
        <div class="title">
          <div v-if="item.remindType === 'ANNOUNCEMENT'" :class="'announcement'"
            >公告</div
          >
          <div v-else-if="item.remindType === '2'" :class="'backlog'"
            >待办作业</div
          >
          <div
            v-else-if="item.remindType === 'PENDING_REMINDERS'"
            :class="'waitCheck'"
            >待审提醒</div
          >
          <div
            v-else-if="item.remindType === 'APPROVAL_RESULT'"
            :class="'result'"
            >审批结果</div
          >
          <div
            v-else-if="item.remindType === 'EARLY_WARNING'"
            :class="'forewarning'"
            >预警提醒</div
          >
        </div>
        <div class="information">
          <div class="interior"> {{ item.title }}</div>
          <div class="right">{{ formatUTCDate(item.createTime) }}</div>
        </div>
      </div>
    </div>
    <div v-else>
      <a-empty />
    </div>
  </a-card>
</template>

<script lang="ts" setup>
  import { ref, reactive } from 'vue';
  import { pullMessageList, messageList } from '@/api/flow';
  import { formatUTCDate } from '@/utils/date';
  import useLoading from '@/hooks/loading';

  const list = () => {
    return {
      listData: [] as messageList[],
    };
  };
  const formModel = ref(list());
  const BusinessType = ref();
  const TypeChange = () => {};
  const { loading, setLoading } = useLoading();
  const pagination = reactive({
    page: 1,
    rows: 20,
    // total: 0,
  });
  const fetchData = async (
    params = {
      ...pagination,
    }
  ) => {
    setLoading(true);
    try {
      const { data } = await pullMessageList(params);
      formModel.value.listData = data.rows;
      //   pagination.total = data.total;
    } catch (err) {
      // you can report use errorHandler or other
    } finally {
      setLoading(false);
    }
  };
  fetchData();
</script>

<style lang="less" scoped>
  :deep(.arco-card-header) {
    background-color: #f2f3f5;
    border: 1px solid #f2f3f5;
  }

  :deep(.arco-card-header-title) {
    font-size: 14px;
    font-weight: bold;
  }

  :deep(.arco-link) {
    font-weight: 500;
    color: #165dff;
  }

  .card {
    border: 1px solid #f2f3f5;
    // min-width: 450px;
  }

  .content {
    width: 100%;
  }

  .cellOut {
    display: flex;
    height: 25px;
    text-align: center;
    line-height: 25px;
    margin-bottom: 10px;
    .title {
      color: #333333;
    }
    .information {
      flex: 1;
      display: flex;
      justify-content: space-between;
      min-width: 0;
      .interior {
        width: 60%;
        text-align: left;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }
      .right {
        width: 25%;
        font-weight: bold;
        color: #cccccc;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }

  // 公告
  .announcement {
    width: 60px;
    background-color: #fff5e6;
    margin-right: 11px;
    color: #fd9f2a;
    font-size: 12px;
  }

  // 待办作业
  .backlog {
    width: 60px;
    background-color: #e5fffa;
    margin-right: 11px;
    color: #41cfca;
    font-size: 12px;
  }

  //待审提醒
  .waitCheck {
    width: 60px;
    background-color: #e4f1fe;
    margin-right: 11px;
    color: #4478f9;
    font-size: 12px;
  }

  // 审批结果
  .result {
    width: 60px;
    background-color: #e0cffa;
    margin-right: 11px;
    color: #865fc8;
    font-size: 12px;
  }

  // 预警提醒
  .forewarning {
    width: 60px;
    background-color: #ffc2c6;
    margin-right: 11px;
    color: #cf5a64;
    font-size: 12px;
  }

  .unfold {
    position: relative;
    width: 150px;
    left: 40%;
  }
</style>
